package bingo.codeweaver.core.metadata;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * Mar 16, 2009 2:01:17 AM BeanMetadata.java
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:
 * ChangeLog:
 */
public class ClassMetadata {
	private List<PropertyMetadata> properties = new ArrayList<PropertyMetadata>();
	private String className;
	private String packageName;
	/**
	 * 主键属性
	 */
	private PropertyMetadata keyProperty;
	
	
	
	public ClassMetadata() {
	}
	
	public ClassMetadata(Class<?> clazz) {
		this.packageName = clazz.getPackage().getName();
		this.className = clazz.getSimpleName();
		Field [] fields = clazz.getDeclaredFields();
		for(Field f : fields){
			properties.add(new PropertyMetadata(f.getName(),f.getType().getName()));
		}
	}
	
	public ClassMetadata(TableMetadata table) {
		this.packageName = null;
		this.className = table.getClassName();
		List<ColumnMetadata> columns = table.getColumns();
		
		for(ColumnMetadata c : columns){
			if(c.isPrimaryKey()){
				keyProperty = new PropertyMetadata(c.getPropertyName(),c.getJavaTypeName());
			}
			properties.add(new PropertyMetadata(c.getPropertyName(),c.getJavaTypeName()));
		}
	}
	
	
	
	public PropertyMetadata getKeyProperty() {
		return keyProperty;
	}

	public void setKeyProperty(PropertyMetadata keyProperty) {
		this.keyProperty = keyProperty;
	}

	public List<PropertyMetadata> getProperties() {
		return properties;
	}

	public void setProperties(List<PropertyMetadata> properties) {
		this.properties = properties;
	}

	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public String getPackageName() {
		return packageName;
	}
	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}
	
	
	
	

}
